package com.learn.datainjector;

public class FieldData {
	private String key;
	private String name;
	private String[] fieldKeys;
	private String[] dataKeys;
	private String fieldVal;
	private String dataKey;
	private String fieldName;
	public FieldData(String key,String name, String[] fieldKeys, String fieldVal) {
		super();
		this.key = key;
		this.name = name;
		this.fieldKeys = fieldKeys;
		this.fieldVal = fieldVal;
		this.dataKey = toDataKey();
		fieldName = fieldKeys[fieldKeys.length-1];
	}
	public String getKey() {
		return key;
	}
	public String getName() {
		return name;
	}
	public String[] getFieldKeys() {
		return fieldKeys;
	}
	public String getFieldVal() {
		return fieldVal;
	}
	
	public boolean isValue(){
		return fieldKeys.length == 1;
	}
	
	public String getDataKey(){
		return dataKey;
	}
	public String[] getDataKeys() {
		return dataKeys;
	}
	public String getFieldName() {
		return fieldName;
	}
	private final String toDataKey(){
		if(dataKey==null&&!isValue()){
			dataKeys = new String[fieldKeys.length-1];
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < fieldKeys.length-1; i++) {
				sb.append(fieldKeys[i]).append(".");
				dataKeys[i] = fieldKeys[i];
			}
			dataKey = sb.substring(0, sb.length()-1);
		}
		return dataKey;
	}
	
}
